package com.weixstudio.controller;


import cn.hutool.jwt.JWT;
import cn.hutool.jwt.signers.JWTSignerUtil;
import com.weixstudio.model.exportModel.UserInfo;
import com.weixstudio.util.ExcelUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
/**
 * @ClassName ExcelController
 * @Description TODO
 * @Author liangw
 * @Date 2021/8/7 11:09
 * @Version 1.0
 **/
@RestController
public class ExcelController {


    @GetMapping("/export")
    public void  export(HttpServletResponse resp) throws IOException {
        OutputStream os = resp.getOutputStream();
        UserInfo a1 = new UserInfo();
        a1.setAge(1);
        a1.setId((long) 1);
        a1.setIdCard("12312312432425");
        a1.setName("张三");
        a1.setPhone("16602063860");

        UserInfo a2 = new UserInfo();
        a2.setAge(2);
        a2.setId((long) 2);
        a2.setIdCard("456567567567");
        a2.setName("李四");
        a2.setPhone("13928765478");
        List<UserInfo> dataList = new ArrayList<UserInfo>();
        dataList.add(a1);
        dataList.add(a2);
        resp.setHeader("content-disposition", "attachment; filename=\"" + URLEncoder.encode("123", "UTF-8") + ".xlsx\"");
        ExcelUtils.exportExcel(os, dataList,  UserInfo.class, null, "用户列表");
    }

//    public static void main(String[] args) {
////        导出使用方法：
//        //导出数据
//        List< SlrEmpSalary> dataList = new ArrayList<SlrEmpSalary>();
//        //导出
//        ExcelUtils.exportExcel(outputStream, dataList,  UserInfo.class, Const.ALL_SELECT_LIST_MAP, exportTitle);
//
//    }

    public static void main(String[] args) {
        byte[] key = "1234567890".getBytes();
        String token = JWT.create()
                .setPayload("sub", "1234567890")
                .setPayload("name", "looly")
                .setPayload("admin", true)
                .setKey(key)
                .sign();
        System.out.println(token);


       // 默认验证HS265的算法
        System.out.println(JWT.of(token).setKey(key).verify());
    }
}
